package validation.jexp;

import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.adapter.ComboBoxAdapter;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.util.ArrayList;

/**
 * JGoodies Binding: ComboBox Adapter Example
 */
public class ComboBoxAdapterExample extends JPanel {

    public ComboBoxAdapterExample() {
        JPanel panel = new JPanel(new FormLayout("p, 2dlu, p:g", "t:p, b:d:g"));
        panel.setBorder(new EmptyBorder(6, 6, 6, 6));
        ArrayList strings = new ArrayList();
        strings.add("Swing");
        strings.add("SWT");
        strings.add("HTML");
        strings.add("Flash");
        strings.add("QT");
        CellConstraints cc = new CellConstraints();
        ValueModel selectionHolder = new ValueHolder("Select A Display Technology");
        ComboBoxAdapter comboBoxAdapter = new ComboBoxAdapter(strings, selectionHolder);
        JComboBox comboBox = new JComboBox();
        comboBox.setModel(comboBoxAdapter);
        panel.add(new JLabel("Combo Box: "), cc.xy(1, 1));
        panel.add(comboBox, cc.xy(3, 1));
        panel.add(new JLabel("Selection: "), cc.xy(1, 2));
        panel.add(BasicComponentFactory.createTextField(selectionHolder), cc.xy(3, 2));
        add(panel);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JGoodiesValidationUtils.showFrame("ComboBox Adapter Example", new ComboBoxAdapterExample());
        });
    }
}
